<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>

<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <!-- START 右侧数据 -->
            <div class="ibox float-e-margins" style="margin-bottom: 0px;">
                <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                    <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                        <div class="form-group">
                            <label class="control-label col-sm-1">渠道:</label>
                            <div class="col-sm-2">
                                <select  name="relatedChannelName"  class="form-control">
                                    <option value="">全部分类</option>
                                    <%for(var chan in channel){%>
                                    <option value="${chan.channelName}"  >${chan.channelName}</option>
                                    <%}%>
                                </select>
                            </div>
                            <label class="control-label col-sm-1">Listing:</label>
                            <div class="col-sm-2">
                                <input type="text" name="relatedListing" class="form-control">
                            </div>
                            <label class="control-label col-sm-1">ASIN:</label>
                            <div class="col-sm-2">
                                <input type="text"  name="relatedAsin" class="form-control">
                            </div>
                            <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                        </div>
                    </form>
                </div>
            </div>
            <!-- START 操作按钮 -->
            <form>
            <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
                <a class="add-btn btn btn-sm btn-success"><i class="fa fa-plus" aria-hidden="true"></i> 新增</a>
                <button  class="layui-btn layui-btn-normal layui-btn-sm" style="margin-top: -6px;margin-left: -4px" id="import-btn"  name="import-btn">
                    <i class="fa fa-plus" aria-hidden="true"></i> 导入Listing
                </button>
                <button  class="export-btn layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -4px">
                    <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
                </button>
                <button  class="layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -2px">
                    <i class="fa fa-download"></i>
                    <a href="/excel/对照表模板.xlsx" style="color: white" download>模板下载</a>
                </button>
            </div>
            </form>
            <!-- END 操作按钮 -->

            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-side-pagination="server"
                   data-page-size="15"
                   data-url="/sea/operate/related/findByCnd.do"
                   class="table table-striped table-hover">
            </table>
            <!-- END 数据表格 -->

            <!-- END 右侧数据 -->
        </div>
    </div>
</div>

<div id="layer_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->

    <div class="container" >
        <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">渠道</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <select id="relatedChannelName" name="relatedChannelName"  class="form-control">
                        <option value="">全部分类</option>
                        <%for(var chan in channel){%>
                        <option value="${chan.channelName}"  >${chan.channelName}</option>
                        <%}%>
                    </select>
                </div>
            </div>

            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">Listing</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="relatedListing" name="relatedListing" value="" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">Asin</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="relatedAsin" name="relatedAsin" value="" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>




<div id="layer_edit_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-edit-form" method="post" autocomplete="off" style="margin: auto">
            <input type="hidden" name="id" id="id">
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">Listing</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text"  id="editListing" name="relatedListing" value="" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">Asin</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="editAsin"  value="" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="edit-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>


<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,layui,upload'}){}%>
<script>


    var $relatedTable = $('#relatedTable'),selections=[];
    $(function(){
        //指定允许上传的文件类型
        //START 表格配置
        $relatedTable.bootstrapTable({
            columns: [
                {
                    title: '渠道',
                    field: 'relatedChannelName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: 'Listing',
                    field: 'relatedListing',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    field: 'relatedAsin',
                    title: 'ASIN',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    field: 'operate',
                    title: '操作',
                    width:200,
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){

                //修改
                $('.edit-related-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    $("#id").val(id);
                    var name=$(this).attr("data-listing");
                    $("#editListing").val(name);
                    var asin=$(this).attr("data-asin");
                    if('null'==asin){
                        $("#editAsin").val('');
                    }else{
                        $("#editAsin").val(asin);
                    }

                    layer.open({
                        type:1,
                        title:'修改Listing',
                        area:['600px','250px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_edit_window')
                    })
                });
            },
            onExpandRow: function (index, row, $detail) {
                InitSubTable(index, row, $detail);
            }
        });
    });
    //操作菜单
    function optFormatter(value,row){
        var content = '<button class="edit-related-btn btn btn-xs btn-info" data-asin="'+row.relatedAsin+'" data-listing="'+row.relatedListing+'" data-val="'+row.id+'" title="修改"><i class="fa fa-edit"></i>  </button>';
        return content;
    }

    $('.add-btn').on('click',function(){//新增
        layer.open({
            type:1,
            title:'添加Listing',
            area:['600px','300px'],
            skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
            shadeClose:false,
            resize: false,
            scrollbar: false,
            maxmin: false,//出现最大化按钮
            content:$('#layer_window')
        })
    });
    //提交表单
    $('.save-btn').on('click',function(){
        layer.confirm('确定要新增当前数据？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            var relatedChannelName=$("#relatedChannelName").val();
            if(relatedChannelName==''){
                parent.layer.msg('请选择渠道！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var relatedListing=$("#relatedListing").val();
            if(relatedListing==''){
                parent.layer.msg('请填写Listing名称！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var relatedAsin=$("#relatedAsin").val();
            if(relatedAsin==''){
                parent.layer.msg('请填写Asin名称！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            layer.closeAll();
            var index=layer.load();
            $.post('/sea/operate/related/save.do',{relatedAsin:relatedAsin,relatedListing:relatedListing,relatedChannelName:relatedChannelName},function(data){
                if( data.ok ){
                    $relatedTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });


    //提交表单
    $('.edit-btn').on('click',function(){
        layer.confirm('确定要新增当前数据？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            var relatedListing=$("#editListing").val();
            if(relatedListing=='' || relatedListing ==null){
                parent.layer.msg('请填写Listing名称！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var relatedAsin=$("#editAsin").val();
            if(relatedAsin=='' || relatedAsin ==null){
                parent.layer.msg('请填写Asin名称！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            layer.closeAll();
            var index=layer.load();
            $.post('/sea/operate/related/usave.do',{id:$("#id").val(),relatedAsin:relatedAsin,relatedListing:relatedListing},function(data){
                if( data.ok ){
                    $relatedTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });


    $('.search-btn').on('click',function(){
           $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/operate/related/findByCnd.do?'+$('#search-form').serialize() });
    });

    $(".export-btn").click(function () {
        window.location.href='/sea/operate/related/export.do?'+$('#search-form').serialize();
    });


    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: '#import-btn', //绑定元素,
            accept:'file',
            url: '/sea/operate/related/import/', //上传接口
            data:{"productMember":$("#productMember").val()},
            before:function () {
                layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $relatedTable.bootstrapTable('refresh');
                        layer.closeAll();
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,time: 5000},function () {
                        layer.closeAll();
                    });

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });
</script>
</body>
</html>
